SQL statement-case when then else end, SQL-case
Output the following results based on the preceding table information:
The following are the database and table structure data:
create table DeptSales(deptID int,SubjMonth int ,sales int ,deptname varchar(50))
insert into
Recently learned SQL in Teradata environment. Here to record the study of the knowledge points, as a record.Directory:
About SQL learning and the online database used
Table Union (join)
SQL Sub-query
Create a new field at select (as, Case time)
Data
PL/SQL daily question: the difference between a CASE statement and a CASE expression: there are many different types of guinea pigs in the world, some of which have identifiable characteristics. For example, the "Abyssinians" skin has a pleated garlands www.2cto.com "Texels" with long curly hair. In contrast, the White
c.t_id=d.t_id left joins student A on a.s_id=b.s_id where D.tname= ' Zhang San '; /*dense_rank () */select E.s_id,e.c_id,e.score from (select s_id, c_id, Score,dense_rank () over (partition by c_id ORDER BY s_id) Rank1 from SC) e left joins course C on e.c_id=c.c_id left joins teacher D on c.t_id=d.t_id where D.tname= ' Zhang San '
and e.rank1=1; Select Top 1* from (select s_id, c_id, Score,dense_rank () up (partition by c_id ORDER by s_id) Rank1 from SC E left J
Oin course C on e.c_id=c
An SQL statement is used in the project, such:
Select sum (price * xiaoliang)/sum (xiaoliang) price from ......
When sum (xiaoliang) = 0, the error of division by 0 will occur. What should I do? At first, I wantProgramProcessing, that is, moving the computing process to the program is obviously troublesome. Later, I found the method of using the case
cannot give the literal value null to EXPRESSION1,2. Coalesce[,k??? ' Les] FunctionsThe COALESCE function compares each expression in the expression list to null and returns the value of the first non-null expression. The COALESCE function has the following structureCOALESCE (Expression1,expression2,........., expressionn)If expression1 equals null, EXPRESSIOIN2 is computed. If the expression2 evaluates to NULL, the function returns EXPRESSION2 and returns null if the result of all expressions
Case has two formats. Simple case functions and case search functions.
-- Simple case Function Case Sex When '1' Then Male' When '2' Then Female' Else 'Others' End -- Case search function
Oracle experiences 1 -- oracle introduction @ basic SQL statement @ conditional query @ sort data theory and case studies1. Oracle IntroductionOracle is the first word for English translation of oracle (Oracle bone inscriptions) Unearthed from Yin. Oracle is the world's largest supplier of information management software and services. It was founded in 1977 and i
SQL server's case when then statement, sqlcase
-- Select DataName,-- Case Code---- When 'w01' then 'male'---- When 'w07 'then' female'---- Else 'others'---- End as Code-- From dbo. HistoryData
Select DataName,(CaseWhen Code = 'w01' then 'male'When Code = 'w07 'then' female'Else 'others'End)From HistoryData
The access d
One of the SQL statement judgment methodsCase has two formats. Simple case functions and case search functions.-- Simple case FunctionCase sexWhen '1' then 'male'When '2' then 'female'Else 'others' end-- Case search functionCase w
Case has two formats. Simple case functions and case search functions.1. Simple case Functions
Case sex when '1' then' male 'when' 2' then' female 'else' others' end
2. Case search functions
This afternoon colleagues asked me a more basic question, when splicing SQL statements, if encountered like the situation what to do.My original writing is a simple concatenation of strings, and later colleagues asked me what to do if I encountered SQL injection. I think about it, it's really a problem.Just on the Internet to find the relevant instructions, the original is so written.As such an
Analysis of two methods of SQL statement row/column conversion case... the application of the when function and the limit function bitsCN.com
/* Create a database */Create database tmpGoUSE tmpGo
/* Create a database Test table */Create table [Scores]([ID] int identity (1, 1)Primary key,[Student] VARCHAR (20 ),[Subject] VARCHAR (30 ),[Score] FLOAT)
Go
Truncate ta
Label:Youdao Written Questions: Server Monitoring table Server_status, when the server state occurs server_status changes in the data table will be inserted a record, state 0 indicates that the shutdown 1 is normal, SQL query Server A's downtime start time and end time, There is a status record for more than one server in the table.
svr_id
Svr_name
Status_time
STATUS
1
A
2013-10-31 00:00:00
SQL statement case when then else end returns a qualified value, sqlcase
Case has two formats
Simple Case functions and Case search functions:
-- Simple Case function
Keyword: case
Case has two formats. Simple Case functions and Case search functions.
-- Simple Case Function
CASE sex
WHEN '1' THEN 'male'
WHEN '2' THEN 'female'
ELSE 'others' END
-- Case
You may be familiar with the IF Else statement, which is used to control the process. A CASE statement statement has a similar effect in the world of SQL. The following is a simple introduction to the use of case statements. Consi
) b where a date=b. Date We might as well review the syntax of case.Case when there are two uses, one is similar to the example in the above simple cases function:Result ' wins '1' negative '20END There is also a case search function:Result=' win '1result=' Negative '20END Where result= ' wins ' can be replaced by other conditional expressions. If more than one case-when expre
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.